package com.ssy.lingxi.settle.accounts.controller;

import com.ssy.lingxi.common.controller.BaseController;
import com.ssy.lingxi.common.response.PageData;
import com.ssy.lingxi.common.response.Wrapper;
import com.ssy.lingxi.dto.request.CommunicationPayVO;
import com.ssy.lingxi.dto.request.InvoiceProveGetVO;
import com.ssy.lingxi.dto.response.InvoiceProveVO;
import com.ssy.lingxi.settle.accounts.model.bo.PayProveBO;
import com.ssy.lingxi.settle.accounts.model.vo.request.*;
import com.ssy.lingxi.settle.accounts.model.vo.response.*;
import com.ssy.lingxi.settle.accounts.service.IMemberReceiptInvoiceService;
import com.ssy.lingxi.settle.accounts.service.IMemberSettlementService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;
import java.util.List;

/**
 * @menu 结算能力-会员结算
 * @author 伍将
 * @date 2020/10/23
 **/
@RestController
@RequestMapping("/settle/accounts/member/settlement")
public class MemberSettlementController extends BaseController {

    @Resource
    private IMemberSettlementService service;

    @Resource
    private IMemberReceiptInvoiceService receiptInvoice;

    /**
     * 应付账款管理-分页查询应付账款结算
     * @author 伍将
     * @date 2020/10/23
     **/
    @RequestMapping(value = "/pagePayableSettlement", method = RequestMethod.GET)
    public Wrapper<PageData<MemberSettlementVO>> pagePayableSettlement(HttpServletRequest httpRequest, @Valid MemberSettlementPageVO pageVO) {
        return service.pagePayableSettlement(getSysUser(httpRequest), pageVO);
    }

    /**
     * 应付账款管理-获取应付账款结算详情
     * @author 伍将
     * @date 2020/10/23
     **/
    @RequestMapping(value = "/getPayableDetail", method = RequestMethod.GET)
    public Wrapper<MemberSettlementDetailVO> getPayableDetail(HttpServletRequest httpRequest, Long id) {
        return service.getPayableDetail(getSysUser(httpRequest), id);
    }

    /**
     * 应付账款管理-付款
     * @author 伍将
     * @date 2020/10/23
     **/
    @RequestMapping("/pay")
    public Wrapper<Void> pay(HttpServletRequest httpRequest, @RequestBody @Valid PayVO payVO) {
        return service.pay(getSysUser(httpRequest), payVO);
    }

    /**
     * 应付账款管理-通联支付:付款
     * @author 彭冬冬
     * @date 2021/11/30
     * @param httpRequest 请求
     * @param communicationPayVO 通联支付数据
     * @return 返回支付页面
     */
    @RequestMapping("/communication/pay")
    public Wrapper<String> communicationPay(HttpServletRequest httpRequest, @RequestBody @Valid CommunicationPayVO communicationPayVO) {
        return service.communicationPay(getSysUser(httpRequest),communicationPayVO);
    }


    /**
     * 应付账款管理-通联支付:获取支付单号
     * @author 彭冬冬
     * @date 2021/12/16
     * @param httpRequest 请求
     * @param id 结算单id
     * @return 结算单通联支付单号
     */
    @RequestMapping(value = "/get/communication/pay/tradeNo", method = RequestMethod.GET)
    public Wrapper<String> getAllInPayTradeNo(HttpServletRequest httpRequest, @RequestParam("id")Long id) {
        return service.getAllInPayTradeNo(getSysUser(httpRequest), id);
    }

    /**
     * @author 彭冬冬
     * @date 2021/12/14
     * @param settlementNo 结算单号
     * @return 返回通联支付调用支付结果
     */
    @RequestMapping(value = "/communication/pay/result", method = RequestMethod.GET)
    public Wrapper<Boolean> getAllInPayResult(HttpServletRequest httpRequest, @RequestParam("settlementNo") String settlementNo) {
        return service.getAllInPayResult(getSysUser(httpRequest),settlementNo);
    }

    /**
     * 应付账款管理-付款方查看凭证
     * @author 伍将
     * @date 2020/10/23
     **/
    @RequestMapping(value = "/getPayablePayProve", method = RequestMethod.GET)
    public Wrapper<List<PayProveBO>> getPayablePayProve(HttpServletRequest httpRequest, Long id) {
        return service.getPayablePayProve(getSysUser(httpRequest), id);
    }

    /**
     * 应付账款管理-通联支付:付款方查看凭证
     * @author 彭冬冬
     * @date 2021/11/30
     * @param httpRequest 请求
     * @param id 结算单id
     * @return 付款方查看凭证
     */
    @RequestMapping(value = "/getPayableCommunicationPayProve", method = RequestMethod.GET)
    public Wrapper<CommunicationPayProveVO> getPayableCommunicationPayProve(HttpServletRequest httpRequest, Long id) {
        return service.getPayableCommunicationPayProve(getSysUser(httpRequest), id);
    }

    /**
     * 应收账款管理-分页查询应收账款结算
     * @author 伍将
     * @date 2020/10/23
     **/
    @RequestMapping(value = "/pageReceivableSettlement", method = RequestMethod.GET)
    public Wrapper<PageData<MemberSettlementVO>> pageReceivableSettlement(HttpServletRequest httpRequest, @Valid MemberSettlementPageVO pageVO) {
        return service.pageReceivableSettlement(getSysUser(httpRequest), pageVO);
    }

    /**
     * 应收账款管理-获取应收账款结算详情
     * @author 伍将
     * @date 2020/10/23
     **/
    @RequestMapping(value = "/getReceivableDetail", method = RequestMethod.GET)
    public Wrapper<MemberSettlementDetailVO> getReceivableDetail(HttpServletRequest httpRequest, Long id) {
        return service.getReceivableDetail(getSysUser(httpRequest), id);
    }

    /**
     * 应收账款管理-确认对账完成
     * @author 伍将
     * @date 2020/10/23
     **/
    @RequestMapping("/confirmAccountComplete")
    public Wrapper<Void> confirmAccountComplete(HttpServletRequest httpRequest, @RequestBody @Valid ConfirmAccountCompleteVO completeVO) {
        return service.confirmAccountComplete(getSysUser(httpRequest), completeVO);
    }

    /**
     * 应收账款管理-确认付款凭证
     * @author 伍将
     * @date 2020/10/23
     **/
    @RequestMapping("/confirmPayProve")
    public Wrapper<Void> confirmPayProve(HttpServletRequest httpRequest, @RequestBody @Valid ConfirmPayProve confirmVO) {
        return service.confirmPayProve(getSysUser(httpRequest), confirmVO);
    }

    /**
     *  应收账款管理-收款方查看凭证
     * @author 伍将
     * @date 2020/10/23
     **/
    @RequestMapping(value = "/getReceivablePayProve", method = RequestMethod.GET)
    public Wrapper<List<PayProveBO>> getReceivablePayProve(HttpServletRequest httpRequest, Long id) {
        return service.getReceivablePayProve(getSysUser(httpRequest), id);
    }

    /**
     * 应收账款管理-通联支付:付款方查看凭证
     * @author 彭冬冬
     * @date 2021/11/30
     * @param httpRequest 请求
     * @param id 结算单id
     * @return 付款方查看凭证
     */
    @RequestMapping(value = "/getReceivableCommunicationPayProve", method = RequestMethod.GET)
    public Wrapper<CommunicationPayProveVO> getReceivableCommunicationPayProve(HttpServletRequest httpRequest, Long id) {
        return service.getReceivableCommunicationPayProve(getSysUser(httpRequest), id);
    }

    /**
     * 应付账款管理-应付账款结算明细-物流单结算明细
     * @author 伍将
     * @date 2020/10/26
     **/
    @RequestMapping(value = "/pagePayableLogisticsSettlement", method = RequestMethod.GET)
    public Wrapper<PageData<MemberLogisticsSettlementVO>> pagePayableLogisticsSettlement(HttpServletRequest httpRequest, @Valid MemberLogisticsSettlementPageVO pageVO) {
        return service.pagePayableLogisticsSettlement(getSysUser(httpRequest), pageVO);
    }

    /**
     * 应收账款管理-应收账款结算明细-物流单结算明细
     * @author 伍将
     * @date 2020/10/26
     **/
    @RequestMapping(value = "/pageReceivableLogisticsSettlement", method = RequestMethod.GET)
    public Wrapper<PageData<MemberLogisticsSettlementVO>> pageReceivableLogisticsSettlement(HttpServletRequest httpRequest, @Valid MemberLogisticsSettlementPageVO pageVO) {
        return service.pageReceivableLogisticsSettlement(getSysUser(httpRequest), pageVO);
    }

    /**
     * 应付账款管理-应付账款结算明细-生产通知单结算明细
     * @author 伍将
     * @date 2020/10/26
     **/
    @RequestMapping(value = "/pagePayableProductionNoticeSettlement", method = RequestMethod.GET)
    public Wrapper<PageData<MemberProductionNoticeSettlementVO>> pagePayableProductionNoticeSettlement(HttpServletRequest httpRequest, @Valid MemberProductionNoticeSettlementPageVO pageVO) {
        return service.pagePayableProductionNoticeSettlement(getSysUser(httpRequest), pageVO);
    }

    /**
     * 应收账款管理-应收账款结算明细-生产通知单结算明细
     * @author 伍将
     * @date 2020/10/26
     **/
    @RequestMapping(value = "/pageReceivableProductionNoticeSettlement", method = RequestMethod.GET)
    public Wrapper<PageData<MemberProductionNoticeSettlementVO>> pageReceivableProductionNoticeSettlement(HttpServletRequest httpRequest, @Valid MemberProductionNoticeSettlementPageVO pageVO) {
        return service.pageReceivableProductionNoticeSettlement(getSysUser(httpRequest), pageVO);
    }

    /**
     * 应付账款管理-应付账款结算明细-订单结算明细
     * @author ds
     * @date 2020/4/6
     **/
    @RequestMapping(value = "/pagePayableOrderSettlement", method = RequestMethod.GET)
    public Wrapper<PageData<MemberOrderSettlementVO>> pagePayableOrderSettlement(HttpServletRequest httpRequest, @Valid MemberOrderSettlementPageVO pageVO) {
        return service.pagePayableOrderSettlement(getSysUser(httpRequest), pageVO);
    }

    /**
     * 应收账款管理-应收账款结算明细-订单结算明细
     * @author ds
     * @date 2020/4/6
     **/
    @RequestMapping(value = "/pageReceivableOrderSettlement", method = RequestMethod.GET)
    public Wrapper<PageData<MemberOrderSettlementVO>> pageReceivableOrderSettlement(HttpServletRequest httpRequest, @Valid MemberOrderSettlementPageVO pageVO) {
        return service.pageReceivableOrderSettlement(getSysUser(httpRequest), pageVO);
    }

    /**
     * 应收账款管理-开票管理-分页查询开票管理列表
     * @author 伍将
     * @date 2020/10/28
     **/
    @RequestMapping(value = "/pageReceiptInvoice", method = RequestMethod.GET)
    public Wrapper<PageData<MemberReceiptInvoiceVO>> pageReceiptInvoice(HttpServletRequest httpRequest, @Valid MemberReceiptInvoicePageVO pageVO) {
        return receiptInvoice.pageReceiptInvoice(getSysUser(httpRequest), pageVO);
    }

    /**
     * 应收账款管理-开票管理-开具发票
     * @author 伍将
     * @date 2020/10/28
     **/
    @RequestMapping("/invoiceProve")
    public Wrapper<Void> invoiceProve(HttpServletRequest httpRequest, @RequestBody @Valid AddReceiptInvoiceVO addVO) {
        return receiptInvoice.invoice(getSysUser(httpRequest), addVO);
    }

    /**
     * 应收账款管理-开票管理-生成批量开票提交数据
     * @param httpRequest 请求
     * @param receiptInvoiceIds 开票id
     * @return 批量开票提交数据
     */
    @RequestMapping(value = "generate/batch/invoice/prove", method = RequestMethod.POST)
    public Wrapper<AddBatchReceiptInvoiceVO> generateInvoiceProveBatch(HttpServletRequest httpRequest, @RequestBody @Valid AddBatchReceiptInvoiceIdsVO receiptInvoiceIds) {
        return receiptInvoice.generateBatchInvoiceProve(getSysUser(httpRequest), receiptInvoiceIds);
    }

    /**
     * 应收账款管理-开票管理-批量开票
     * @param httpRequest 请求
     * @param batchAddVO 批量开票数据
     * @return 开票结果
     */
    @RequestMapping(value ="/batch/invoice/prove", method = RequestMethod.POST)
    public Wrapper<Void> batchInvoiceProve(HttpServletRequest httpRequest, @RequestBody @Valid AddBatchReceiptInvoiceVO batchAddVO) {
        return receiptInvoice.batchInvoiceProve(getSysUser(httpRequest),batchAddVO);
    }
    /**
     * 应收账款管理-开票管理-查看发票
     * @param httpRequest 请求
     * @param id id
     * @return 发票列表
     */
    @RequestMapping(value = "/getInvoiceProveDetail", method = RequestMethod.GET)
    public Wrapper<MemberReceiptInvoiceDetailVO> getInvoiceProveDetail(HttpServletRequest httpRequest, Long id) {
        return receiptInvoice.getInvoiceProveDetail(getSysUser(httpRequest), id);
    }

    /**
     * 应收账款管理-开票管理-开具退货发票
     * @author 伍将
     * @date 2020/10/28
     **/
    @RequestMapping("/invoiceByReturn")
    public Wrapper<Void> invoiceByReturn(HttpServletRequest httpRequest, @RequestBody @Valid AddReceiptInvoiceListVO addVO) {
        return receiptInvoice.invoiceByReturn(getSysUser(httpRequest), addVO);
    }

    /**
     * 应收账款管理-开票管理-查看退货发票
     * @author 伍将
     * @date 2021/1/27
     **/
    @RequestMapping(value = "/getReturnInvoiceProveDetail", method = RequestMethod.GET)
    public Wrapper<List<MemberReturnReceiptInvoiceDetailVO>> getReturnInvoiceProveDetail(HttpServletRequest httpRequest, Long id) {
        return receiptInvoice.getReturnInvoiceProveDetail(getSysUser(httpRequest), id);
    }

    /**
     * 获取发票凭证
     * @author 伍将
     * @date 2021/3/10
     **/
    @RequestMapping(value = "/getInvoiceProve", method = RequestMethod.GET)
    public Wrapper<List<InvoiceProveVO>> getInvoiceProve(HttpServletRequest httpRequest, @Valid InvoiceProveGetVO getVO) {
        return receiptInvoice.getInvoiceProve(getSysUser(httpRequest), getVO);
    }
}
